package com.lc.rabbitmq.listener;

import com.lc.rabbitmq.consumer.OrderConsumer;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;

/**
 * @author liuc
 * @date 2021/8/16
 * @description
 **/
@Component
public class MyRabbitListener {

    @Autowired
    OrderConsumer orderConsumer;

    //监听死信交换器的消息
    @RabbitListener(queues = "queue.dlx")
    public void onMessage(Message message, Channel channel) throws UnsupportedEncodingException {
        //这里收到的消息已经是过期的付款单了
        //1.获取消息内容
        String msg = new String(message.getBody(),"utf-8");
        System.out.println("consumer msg : " + msg);
        //2.拿到订单id
        String orderId = msg.split(":")[1];
        orderConsumer.expire(orderId);
    }

}
